package com.lhn;

import com.lhn.dao.BookDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * @author lhn
 * @date 2024-08-19 11:21
 */

public class App {
    public static void main(String[] args) {
        //1.加载类路径下的application.xml文件
        ApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");

        //2.使用文件系统需要使用绝对路径
//        ApplicationContext ctx = new FileSystemXmlApplicationContext(
//                "E:\\DataStructureCode\\spring-learn\\learn-09-container\\src\\main\\resources\\application.xml"
//        );

        //获取bean的三种方式
        //1.根据bean的id获取
//        BookDao bookDao = (BookDao) ctx.getBean("bookDao");

        //2.根据bean的名称获取指定类型
//        BookDao bookDao = ctx.getBean("bookDao", BookDao.class);

        //3.根据bean的类型获取
        //容器中只能有唯一的一个BookDao bean
        BookDao bookDao = ctx.getBean(BookDao.class);
        bookDao.save();
    }
}
